<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-10-08 17:02
 *
 * Version: 2.0
 */

namespace App\Modules\DataCenter\Transformers;


use League\Fractal\TransformerAbstract;

class getContributionListTransformer extends TransformerAbstract
{
	private $list;
	public function __construct($list)
	{
		$this->list = $list;
	}

	public function transformer()
	{
		$newList = $this->list['items'];
		$result = [];
		if(isset($newList)){
			foreach ($newList as $v){
				if($v['category']==1){
					$result[] = [
						'image'      => isset($v['order']['items_one']['service']['category']['picture']['image']) ? $v['order']['items_one']['service']['category']['picture']['image'] : '',
						'title'      => isset($v['order']['items_one']['service_name']) ? $v['order']['items_one']['service_name'] : '',
						'content'    => '',
						'created_at' => $v['created_at'],
						'amount'     => 0,
						'profit'     => $v['profit'],
					];
				}else if($v['category'] ==2 ){
					$result[] = [
						'image'      =>config('constant.message.wx_image'),
						'title'      => isset($v['order']['card']['name']) ? $v['order']['card']['name'] : '',
						'content'    => '',
						'created_at' => $v['created_at'],
						'amount'     => 0,
						'profit'     => $v['profit'],
					];
				}else if($v['category'] ==3 ){
					$result[] = [
						'image'      => isset($v['order']['goods']['picture']['image']) ? $v['order']['goods']['picture']['image'] : '',
						'title'      => isset($v['order']['goods']['small_name']) ? $v['order']['goods']['small_name'] : '',
						'content'    => '',
						'created_at' => $v['created_at'],
						'amount'     => 0,
						'profit'     => $v['profit'],
					];
				}
			}
			$this->list['items'] = $result;
		}
		return $this->list;
	}
}